package com.cloudshadow.platform.infrastructure.core.aspect;

import com.alibaba.fastjson.JSON;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;

@Aspect
@Configuration
//@Order(AspectOrders.LOG_ORDER)
public class LogAspect extends CoreAspect{

	private static final Logger LOGGER = LoggerFactory.getLogger(LogAspect.class);

	@Around(value = "pointCut()")
	protected Object aroundAdvice(ProceedingJoinPoint pjp) throws Throwable {

		long costTimeStart = System.currentTimeMillis();
		Object o = pjp.proceed();
//		不打印返回数据
//		LOGGER.debug("print API返回的数据如下：");
//		if(o != null){
//			LOGGER.debug(JSON.toJSON(o).toString());
//		}
		LOGGER.info("请求方法：");
		LOGGER.info(pjp.getSignature().getDeclaringTypeName() +
				"." + pjp.getSignature().getName());
		LOGGER.info("请求参数：");
		LOGGER.info(JSON.toJSON(pjp.getArgs()).toString());
		LOGGER.info("api请求总耗时：" + (System.currentTimeMillis() - costTimeStart) + "ms");
		return o;
	}

}
